/**
 * Created by admin on 2016/11/25.
 */
var order = function () {
    var goExpressDetail = function () {
        $('.expressDetail').on('click',function () {
            if (getUserLoginStatus()) {
                var expressCode = $(this).attr('data-expressCode');
                var expressNO = $(this).attr('data-expressNO');
                var expressName = $(this).attr('data-expressName');
                var imgUrl = $('img:first').attr('src');
                window.localStorage.setItem('imgUrl',imgUrl);
                window.location.href='/express/?expressCode='+expressCode+'&expressNO='+expressNO+'&expressName='+expressName;
            } else {
                doLogin();
            }
        });
    };

    var refund = function () {
        $('.refundOrder').click(function () {
            var price = $(this).attr('data-price');
            var count = $(this).attr('data-count');
            var orderId = $(this).attr('data-orderId');
            var refundProductId = $(this).attr('data-productId');
            var refundData = {
                expressPrice:0,
                refundMoney:price*count,
                orderId:orderId,
                refundProductId:refundProductId
            };
            var userId = getUserLoginStatus(true);
            if(userId){
                refundData.userId = userId;
                var params = new Base64().encode(JSON.stringify(refundData));
                window.location.href = 'http://'+ REFUND_HOST +'/refundType?params='+params+'&userId='+getUserLoginStatus(true)+'&from=koudai';
            }else{
                doLogin();
            }
        })
    };

    var viewRefund = function () {
        $('.refundProgress').click(function () {
            var returnId = $(this).attr('data-refundOrderId');
            var userId = getUserLoginStatus(true);
            if(userId){
                window.location.href = 'http://'+ REFUND_HOST +'/refundProgress?orderReturnId='+returnId+'&from=koudai';
            }else{
                doLogin();
            }
        })
    };
    return{
        init:function(){
            goExpressDetail();
            refund();
            viewRefund();
        }
    }
}();